<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"     
    >
      <el-form-item label="时间">
        <el-date-picker
          v-model="daterangeRecordTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:ckresult:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ckresult:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <span class="span1">绿色：已完成</span>
    <el-table
      v-loading="loading"
      :data="ckresultList"
      @selection-change="handleSelectionChange"
      :cell-style="tableColor"
      :header-cell-style="{ background: 'rgb(64, 158, 255)', color: '#fff' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="时间"
        align="center"
        prop="recordTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="导热油化蜡"
        align="center"
        prop="dryhlCheck"
        width="100"
      />
      <el-table-column label="网带线一" align="center" prop="wdxyCheck" />
      <el-table-column label="压柱机A" align="center" prop="ylzjaCheck" />
      <el-table-column label="压柱机B" align="center" prop="ylzjbCheck" />
      <el-table-column label="穿灯芯机1" align="center" prop="cdxjaCheck" />
      <el-table-column label="穿灯芯机2" align="center" prop="cdxjbCheck" />
      <el-table-column
        label="放蜡柱机A"
        align="center"
        prop="flzjaCheck"
        width="120"
      />
      <el-table-column
        label="放蜡柱机B"
        align="center"
        prop="flzjbCheck"
        width="120"
      />
      <el-table-column label="网带线二" align="center" prop="wdxeCheck" />
      <el-table-column label="自动上线" align="center" prop="zdsxCheck" />
      <el-table-column
        label="网带线一自动下线"
        align="center"
        prop="wdxyzdxxCheck"
      />
      <el-table-column
        label="网带线二自动上线"
        align="center"
        prop="wdxezdsxCheck"
      />
      <el-table-column
        label="网带线二自动下线"
        align="center"
        prop="wdxezdxxCheck"
      />
      <el-table-column label="预热罩" align="center" prop="yrzCheck" />
      <el-table-column label="制冷系统1" align="center" prop="zlaCheck" />
      <el-table-column label="制冷系统2" align="center" prop="zlbCheck" />
      <el-table-column label="发泡机" align="center" prop="fpjCheck" />
      <el-table-column
        label="发泡灌装机"
        align="center"
        prop="fpgzjCheck"
        width="120"
      />
      <el-table-column label="灌装机" align="center" prop="gzjCheck" />
      <el-table-column
        label="螺旋提升机1"
        align="center"
        prop="lxtsxaCheck"
        width="120"
      />
      <el-table-column
        label="螺旋提升机2"
        align="center"
        prop="lxtsxbCheck"
        width="120"
      />
      <el-table-column
        label="底面贴标机"
        align="center"
        prop="dmtbjCheck"
        width="120"
      />
      <el-table-column
        label="侧面贴标机"
        align="center"
        prop="cmtbjCheck"
        width="120"
      />
      <el-table-column
        label="一字封箱机"
        align="center"
        prop="yzfxjCheck"
        width="120"
      />
      <el-table-column
        label="工字封箱机"
        align="center"
        prop="gzfxjCheck"
        width="120"
      />
      <!-- 
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ckresult:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:ckresult:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改点检完成情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="点检报表的id" prop="adminCheckId">
          <el-input
            v-model="form.adminCheckId"
            placeholder="请输入点检报表的id"
          />
        </el-form-item>
        <el-form-item label="导热油化蜡" prop="dryhlCheck">
          <el-input v-model="form.dryhlCheck" placeholder="请输入导热油化蜡" />
        </el-form-item>
        <el-form-item label="网带线一" prop="wdxyCheck">
          <el-input v-model="form.wdxyCheck" placeholder="请输入网带线一" />
        </el-form-item>
        <el-form-item label="压柱机A" prop="ylzjaCheck">
          <el-input v-model="form.ylzjaCheck" placeholder="请输入压柱机A" />
        </el-form-item>
        <el-form-item label="压柱机B" prop="ylzjbCheck">
          <el-input v-model="form.ylzjbCheck" placeholder="请输入压柱机B" />
        </el-form-item>
        <el-form-item label="穿灯芯机1" prop="cdxjaCheck">
          <el-input v-model="form.cdxjaCheck" placeholder="请输入穿灯芯机1" />
        </el-form-item>
        <el-form-item label="穿灯芯机2" prop="cdxjbCheck">
          <el-input v-model="form.cdxjbCheck" placeholder="请输入穿灯芯机2" />
        </el-form-item>
        <el-form-item label="放蜡柱机A" prop="flzjaCheck">
          <el-input v-model="form.flzjaCheck" placeholder="请输入放蜡柱机A" />
        </el-form-item>
        <el-form-item label="放蜡柱机B" prop="flzjbCheck">
          <el-input v-model="form.flzjbCheck" placeholder="请输入放蜡柱机B" />
        </el-form-item>
        <el-form-item label="网带线二" prop="wdxeCheck">
          <el-input v-model="form.wdxeCheck" placeholder="请输入网带线二" />
        </el-form-item>
        <el-form-item label="自动上线" prop="zdsxCheck">
          <el-input v-model="form.zdsxCheck" placeholder="请输入自动上线" />
        </el-form-item>
        <el-form-item label="网带线一自动下线" prop="wdxyzdxxCheck">
          <el-input
            v-model="form.wdxyzdxxCheck"
            placeholder="请输入网带线一自动下线"
          />
        </el-form-item>
        <el-form-item label="网带线二自动上线" prop="wdxezdsxCheck">
          <el-input
            v-model="form.wdxezdsxCheck"
            placeholder="请输入网带线二自动上线"
          />
        </el-form-item>
        <el-form-item label="网带线二自动下线" prop="wdxezdxxCheck">
          <el-input
            v-model="form.wdxezdxxCheck"
            placeholder="请输入网带线二自动下线"
          />
        </el-form-item>
        <el-form-item label="预热罩" prop="yrzCheck">
          <el-input v-model="form.yrzCheck" placeholder="请输入预热罩" />
        </el-form-item>
        <el-form-item label="制冷系统1" prop="zlaCheck">
          <el-input v-model="form.zlaCheck" placeholder="请输入制冷系统1" />
        </el-form-item>
        <el-form-item label="制冷系统2" prop="zlbCheck">
          <el-input v-model="form.zlbCheck" placeholder="请输入制冷系统2" />
        </el-form-item>
        <el-form-item label="发泡机" prop="fpjCheck">
          <el-input v-model="form.fpjCheck" placeholder="请输入发泡机" />
        </el-form-item>
        <el-form-item label="发泡灌装机" prop="fpgzjCheck">
          <el-input v-model="form.fpgzjCheck" placeholder="请输入发泡灌装机" />
        </el-form-item>
        <el-form-item label="灌装机" prop="gzjCheck">
          <el-input v-model="form.gzjCheck" placeholder="请输入灌装机" />
        </el-form-item>
        <el-form-item label="螺旋提升机1" prop="lxtsxaCheck">
          <el-input
            v-model="form.lxtsxaCheck"
            placeholder="请输入螺旋提升机1"
          />
        </el-form-item>
        <el-form-item label="螺旋提升机2" prop="lxtsxbCheck">
          <el-input
            v-model="form.lxtsxbCheck"
            placeholder="请输入螺旋提升机2"
          />
        </el-form-item>
        <el-form-item label="底面贴标机" prop="dmtbjCheck">
          <el-input v-model="form.dmtbjCheck" placeholder="请输入底面贴标机" />
        </el-form-item>
        <el-form-item label="侧面贴标机" prop="cmtbjCheck">
          <el-input v-model="form.cmtbjCheck" placeholder="请输入侧面贴标机" />
        </el-form-item>
        <el-form-item label="一字封箱机" prop="yzfxjCheck">
          <el-input v-model="form.yzfxjCheck" placeholder="请输入一字封箱机" />
        </el-form-item>
        <el-form-item label="工字封箱机" prop="gzfxjCheck">
          <el-input v-model="form.gzfxjCheck" placeholder="请输入工字封箱机" />
        </el-form-item>
        <el-form-item label="时间" prop="recordTime">
          <el-date-picker
            clearable
            v-model="form.recordTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCkresult,
  getCkresult,
  delCkresult,
  addCkresult,
  updateCkresult,
} from "@/api/system/ckresult";

export default {
  name: "Ckresult",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 点检完成情况表格数据
      ckresultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 时间时间范围
      daterangeRecordTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        adminCheckId: null,
        dryhlCheck: null,
        wdxyCheck: null,
        ylzjaCheck: null,
        ylzjbCheck: null,
        cdxjaCheck: null,
        cdxjbCheck: null,
        flzjaCheck: null,
        flzjbCheck: null,
        wdxeCheck: null,
        zdsxCheck: null,
        wdxyzdxxCheck: null,
        wdxezdsxCheck: null,
        wdxezdxxCheck: null,
        yrzCheck: null,
        zlaCheck: null,
        zlbCheck: null,
        fpjCheck: null,
        fpgzjCheck: null,
        gzjCheck: null,
        lxtsxaCheck: null,
        lxtsxbCheck: null,
        dmtbjCheck: null,
        cmtbjCheck: null,
        yzfxjCheck: null,
        gzfxjCheck: null,
        recordTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
   
  },
  methods: {
    tableColor({ row, column }) {
      if (column.label === "穿灯芯机1") {
        if (row.cdxjaCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "穿灯芯机2") {
        if (row.cdxjbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "侧面贴标机") {
        if (row.cmtbjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "底面贴标机") {
        if (row.dmtbjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "导热油化蜡") {
        if (row.dryhlCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "放蜡柱机A") {
        if (row.flzjaCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "放蜡柱机B") {
        if (row.flzjbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "发泡灌装机") {
        if (row.fpgzjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "灌装机") {
        if (row.gzjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "发泡机") {
        if (row.cdxjbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "工字封箱机") {
        if (row.gzfxjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "螺旋提升机1") {
        if (row.lxtsxaCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "螺旋提升机2") {
        if (row.lxtsxbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线二") {
        if (row.wdxeCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线二自动上线") {
        if (row.wdxezdsxCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线二自动下线") {
        if (row.wdxezdxxCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线一") {
        if (row.wdxyCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线二自动上线") {
        if (row.wdxezdxxCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "网带线一自动下线") {
        if (row.wdxyzdxxCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "压柱机A") {
        if (row.ylzjaCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "压柱机B") {
        if (row.ylzjbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "预热罩") {
        if (row.yrzCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "一字封箱机") {
        if (row.yzfxjCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "自动上线") {
        if (row.zdsxCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "制冷系统1") {
        if (row.zlaCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      } else if (column.label === "制冷系统2") {
        if (row.zlbCheck === "已完成") {
          return "background-color:#58d88e;color:#fff";
        }
      }
    },
    /** 查询点检完成情况列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRecordTime && "" != this.daterangeRecordTime) {
        this.queryParams.params["beginRecordTime"] =
          this.daterangeRecordTime[0];
        this.queryParams.params["endRecordTime"] = this.daterangeRecordTime[1];
      }
      listCkresult(this.queryParams).then((response) => {
        console.log(response);
        this.ckresultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        adminCheckId: null,
        dryhlCheck: null,
        wdxyCheck: null,
        ylzjaCheck: null,
        ylzjbCheck: null,
        cdxjaCheck: null,
        cdxjbCheck: null,
        flzjaCheck: null,
        flzjbCheck: null,
        wdxeCheck: null,
        zdsxCheck: null,
        wdxyzdxxCheck: null,
        wdxezdsxCheck: null,
        wdxezdxxCheck: null,
        yrzCheck: null,
        zlaCheck: null,
        zlbCheck: null,
        fpjCheck: null,
        fpgzjCheck: null,
        gzjCheck: null,
        lxtsxaCheck: null,
        lxtsxbCheck: null,
        dmtbjCheck: null,
        cmtbjCheck: null,
        yzfxjCheck: null,
        gzfxjCheck: null,
        recordTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRecordTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加点检完成情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getCkresult(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改点检完成情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCkresult(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCkresult(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除点检完成情况编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCkresult(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/ckresult/export",
        {
          ...this.queryParams,
        },
        `ckresult_${new Date().getTime()}.xlsx`
      );
    },
   
  },
};
</script>
<style scoped>
.span1 {
  color: #58d88e;
  float: right;
}
</style>
